<?php 

/**
 *封装公共函数调用
 *$filed 查询字段 $table 查询表明 
 *$where 查询条件  $dese 倒序正序 
 *$limit1,$limit2 跳转条数
 */

function getone($filed,$table,$where,$order){
	$Model = new \Think\Model();
	if(empty($filed)){
		$filed ='*';
	}
	
	if(empty($where) || $where==0 ){
		$sql = "SELECT $filed FROM $table ORDER BY $order DESC LIMIT 0,1";
	}else{

		foreach($where as $key =>$val){
			$count .= "$key=$val".' AND ';
		}
		$count = rtrim($count, 'AND '); 
		$sql = "SELECT $filed FROM $table WHERE $count ORDER BY $order DESC LIMIT 0,1";
	}
	
	return $Model->query($sql);
	
}

function getarray($table,$where){
	$Model = new \Think\Model();
	if(empty($where) || $where==0 ){
		$sql = "SELECT * FROM $table";
	}else{

		foreach($where as $key =>$val){
			$count .= "$key=$val".' AND ';
		}
		$count = rtrim($count, 'AND '); 

		$sql = "SELECT * FROM  $table WHERE $count";
	}
	return $Model->query($sql);
}

function getfield($filed,$table,$where){

	$Model = new \Think\Model();

	if(empty($filed)){
		$filed ='*';
	}
	if(empty($where) || $where==0 ){
		$sql = "SELECT $filed FROM $table";
	}else{

		foreach($where as $key =>$val){
			$count .= "$key=$val".' AND ';
		}
		$count = rtrim($count, 'AND '); 
		$sql = "SELECT $filed FROM $table WHERE $count";
	}
	return $Model->query($sql);
}

function getorder($filed,$table,$where,$order){
	$Model = new \Think\Model();
	if(empty($filed)){
		$filed ='*';
	}
	if(empty($where) || $where==0 ){
		$sql = "SELECT $filed FROM $table ORDER BY $order DESC";
	}else{
		foreach($where as $key =>$val){
			$count .= "$key=$val".' AND ';
		}
		$count = rtrim($count, 'AND '); 
		$sql = "SELECT $filed FROM $table WHERE $count ORDER BY $order DESC";
	}
	return $Model->query($sql);
}

function getlimit($filed,$table,$where,$order,$limit1,$limit2){
	$Model = new \Think\Model();
	if(empty($filed)){
		$filed ='*';
	}
	if(empty($where) || $where==0 ){
		$sql = "SELECT $filed FROM $table ORDER BY $order DESC LIMIT $limit1,$limit2";
	}else{

		foreach($where as $key =>$val){
			$count .= "$key=$val".' AND ';
		}
		$count = rtrim($count, 'AND '); 

		$sql = "SELECT $filed FROM $table WHERE $count ORDER BY $order DESC LIMIT $limit1,$limit2";
	
	}
	return $Model->query($sql);
}

function getcount($table,$where){
	$Model = new \Think\Model();
	foreach($where as $key =>$val){
			$count .= "$key=$val".' AND ';
	}
	$count = rtrim($count, 'AND '); 
	$sql = "SELECT count(*) FROM $table WHERE $count";
	
	return $Model->query($sql);
}
function getupdate($table,$save,$where){
	$Model = new \Think\Model();
	foreach($save as $key =>$val){
		$up .= "$key=$val".',';
	}
	$update = rtrim($up, ',');

	foreach($where as $k =>$v){
		$list .= "$k=$v".',';
	}
	$while = rtrim($list, ',');

	$sql = "UPDATE $table SET $update WHERE $while";
	
	return $Model->execute($sql);

}

function qingniuAccessKey(){
	$AccessKey  = 'jpZ22-1VXgQ9NyNZfF7PqLOR23Txn24-T0Qowg4d';
	return  $AccessKey;
}
function qingniuSecretKey(){
	$SecretKey  ='A4RPXThsdFzro2n0aPpWr-qFKtcw2puMVIfXVMOH';
	return $SecretKey;
}
function qingniuspace(){
	$space  ='jswlbbs';
	return $space;
}
function qiniuhttp(){
	$url = 'p2ab6qgbc.bkt.clouddn.com';
	return $url;
}

